<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue事件绑定基础</title>
    <script src="https://unpkg.com/vue@3.4.0"></script>
    <style>
      button {
        margin: 0 10px 0 10px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h2>事件绑定演示</h2>

      <!-- 基础点击事件 -->
      <button v-on:click="handleClick">v-on语法</button>
      <button @click="handleClick">@简写语法</button>

      <!-- 内联处理器 -->
      <button @click="count++">计数: {{count}}</button>

      <!-- 传递参数 -->
      <button @click="greet('Vue')">打招呼</button>

      <!-- 获取事件对象 -->
      <button @click="showEvent">显示事件信息</button>

      <p>{{message}}</p>
    </div>

    <script>
      const { createApp, ref } = Vue

      const App = {
        setup() {
          const count = ref(0)
          const message = ref('等待事件触发...')

          const handleClick = () => {
            message.value = '按钮被点击了！'
          }

          const greet = name => {
            message.value = `Hello, ${name}!`
          }

          const showEvent = event => {
            message.value = `事件类型: ${event.type}, 目标元素: ${event.target.tagName}`
          }

          return {
            count,
            message,
            handleClick,
            greet,
            showEvent
          }
        }
      }

      createApp(App).mount('#app')
    </script>
  </body>
</html>
